package com.liustar.common.util;

import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

import java.util.List;

/**
 * 支持加密配置文件插件
 *
 * @author Leo
 * @date 2017/2/4
 */
public class EncryptPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {

    private List<String> encryptProperties;

    public void setEncryptProperties(List<String> encryptProperties) {
        this.encryptProperties = encryptProperties;
    }

    /**
     * 解密指定propertyName的加密属性值
     *
     * @param propertyName
     * @param propertyValue
     * @return
     */
    @Override
    protected String convertProperty(String propertyName, String propertyValue) {
        for (String p : encryptProperties) {
            if (p.equalsIgnoreCase(propertyName)) {
                return CryptoUtil.decryptAES(propertyValue);
            }
        }
        return super.convertProperty(propertyName, propertyValue);
    }

}
